/*
 * class pineapple.ChannelDevice
 *
 * March 28, 2012 
 * @authors Roman Kotusev, Darjuš Ilcevič, Kristis Vaškys
 */

package pineapple;

/**
 *
 * @author Ronny
 */

public class ChannelDevice {
    
    private RealMachineModel GUI;   // user interface
    
    public ChannelDevice(RealMachineModel ui) {
        GUI = ui;
    }
    
    public String getFilePath() {
        while (GUI.executeButtonClick == false) {}
        return GUI.getAbsolutePath().replace("\\", "\\\\");
    }
    
    public String wordInput() {
        String word;
        GUI.rAddConsoleField(": Prasymas ivesti zodi:");
        GUI.enableEnterButton();
        while((GUI.enterButtonClick == false) 
                && (GUI.closeButtonClick == false)) {}
        if (GUI.closeButtonClick == true) return null;
        word = GUI.getInput();
        GUI.disableEnterButton();
        GUI.enterButtonClick = false;
        GUI.rAddConsoleField(word);
        return word;
    }
    
    public Integer numberInput() {
        Integer number=0;
        GUI.rAddConsoleField(": Prasymas ivesti skaiciu:");
        GUI.enableEnterButton();
        while((GUI.enterButtonClick == false) 
                && (GUI.closeButtonClick == false)) {}
        if (GUI.closeButtonClick == true) return null;
        try {
            number = Integer.parseInt(GUI.getInput());
        } catch (NumberFormatException e){
            GUI.showAlertDialog("Skaiciaus ivedimo klaida");
            System.err.println("Damn, that's no Number!");
        }
        GUI.rAddConsoleField(number + "");
        GUI.enterButtonClick = false;
        GUI.disableEnterButton();
        return number;
    }
    
    public void wordOutput(String word) {
        GUI.rAddConsoleField(word);
    }
    
    public void numberOutput(Integer number) {
        GUI.rAddConsoleField(number + "");
    }
    
    public void errorOutput(String msg) {
        GUI.showAlertDialog(msg);
    }
    
}